package com.aaa.gs.service.impl;

import com.aaa.common.entity.ProductExamine;
import com.aaa.common.vo.ProductVO;
import com.aaa.gs.dao.ProductExamineDao;
import com.aaa.gs.service.ProductExamineService;
import com.aaa.gs.service.ProductService;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.ResultStatus;
import com.aaa.common.vo.Page;


import javax.annotation.Resource;

/**
 * 产品审核表，存储所有产品审核相关信息(ProductExamine)表服务实现类
 *
 * @author makejava
 * @since 2025-09-20 17:11:18
 */
@Service("productExamineService")
public class ProductExamineServiceImpl implements ProductExamineService {
    @Resource
    private ProductExamineDao productExamineDao;
    @Resource
    private ProductService productService;

    /**
     * 通过ID查询单条数据
     *
     * @param productExamineId 主键
     * @return 实例对象
     */
    @Override
    public ProductExamine queryById(Integer productExamineId) {
        return this.productExamineDao.queryById(productExamineId);
    }

    /**
     * 分页查询
     *
     * @param page 筛选条件
     * @return 查询结果
     */
    @Override
    public PageInfo queryByPage(Page<ProductExamine> page) {
        //分页操作  分页参数一定要进行传递
        if (page == null || page.getPageNo() == null || page.getPageNo() == 0 || page.getPageSize() == null || page.getPageSize() == 0) {
            //进行业务编写时，可以抛出自定义异常
            throw new CustomException(ResultStatus.PARAM_NOT_EMPTY.getReturnCode(),
                    ResultStatus.PARAM_NOT_EMPTY.getReturnMessage());
        }
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        //获取查询对象
        ProductExamine productExamine = page.getData();
        return new PageInfo(productExamineDao.queryAllByLimit(productExamine));
    }

    /**
     * 新增数据
     *
     * @param productExamine 实例对象
     * @return 实例对象
     */
    @Override
    public ProductExamine insert(ProductExamine productExamine) {
        this.productExamineDao.insert(productExamine);
        return productExamine;
    }

    /**
     * 修改数据
     *
     * @param productExamine 实例对象
     * @return 实例对象
     */
    @Override
    public ProductExamine update(ProductExamine productExamine) {
        this.productExamineDao.update(productExamine);
        //修改商品审核状态
        ProductVO productVO = productService.queryById(productExamine.getProductId());
        productVO.setExamineStatus(productExamine.getIsExamine());
        productService.update(productVO);
        return this.queryById(productExamine.getProductExamineId());
    }

    /**
     * 通过主键删除数据
     *
     * @param productExamineId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer productExamineId) {
        return this.productExamineDao.deleteById(productExamineId) > 0;
    }
}
